package kuangshen.priproty;

/**
 * @program: liangt
 * @description: 测试优先级
 * @author: liangt
 * @create: 2021-03-03 13:28
 */
public class TestPriority {

    public static void main(String[] args) {
        //主线程默认优先级
        System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());

        //子线程优先级
        Thread thread1 = new Thread(new MyPriority(),"子线程");
        Thread thread2 = new Thread(new MyPriority(),"子线程");
        Thread thread3 = new Thread(new MyPriority(),"子线程");
        Thread thread4 = new Thread(new MyPriority(),"子线程");
        Thread thread5 = new Thread(new MyPriority(),"子线程");
        Thread thread6 = new Thread(new MyPriority(),"子线程");
        thread1.start();
        thread2.setPriority(1);
        thread2.start();
        thread3.setPriority(4);
        thread3.start();
        thread4.setPriority(10);
        thread4.start();
        thread5.setPriority(-1);
        thread5.start();
        thread6.setPriority(11);
        thread6.start();
    }
}

class MyPriority implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
    }
}